/*
 * Galaxium Messenger
 * 
 * Copyright (C) 2008 Philippe Durand <draekz@gmail.com>
 * 
 * License: GNU General Public License (GPL)
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;

using Anculus.Core;

namespace Galaxium.Protocol.GaduGadu
{
	public class LoginCommand : GaduCommand
    {
		private int _number;
        private byte _hash_type = GaduConstants.GG_LOGIN_HASH_SHA1;
        private byte[] _hash;
        private int _status = 2;
        private int _version = GaduConstants.GG_VERSION;
        private byte _unknown1 = 0x00;
        private IPAddress _local_ip;
        private short _local_port = 8074;
        private IPAddress _external_ip;
        private short _external_port = 8074;
        private byte _image_size = 0;
        private byte _unknown2 = 0xbe;
        private byte[] _description;
        private int _time = 0;
        
        public int Number
        {
            get { return _number; }
            set { _number = value; }
        }
		
		public byte HashType
		{
			get { return _hash_type; }
			set { _hash_type = value; }
		}
		
        public byte[] Hash
        {
            get { return _hash; }
            set
            {
            	_hash = new byte[64];
                for (int i = 0; i < value.Length; i++)
                    _hash[i] = value[i];
            }
        }
        
        public int Status
        {
            get { return _status; }
            set { _status = value; }
        }
        
        public int Version
        {
            get { return _version; }
            set { _version = value; }
        }
        
        public IPAddress localIP
        {
            get { return _local_ip; }
            set { _local_ip = value; }
        }
        
        public short LocalPort
        {
            get { return _local_port; }
            set { _local_port = value; }
        }
		
        public IPAddress ExternalIP
        {
            get { return _external_ip; }
            set { _external_ip = value; }
        }
		
        public short ExternalPort
        {
            get { return _external_port; }
            set { _external_port = value; }
        }
		
        public byte ImageSize
        {
            get { return _image_size; }
            set { _image_size = value; }
        }
		
        public byte[] Description
        {
            get { return _description; }
            set { _description = value; }
        }
		
        public int Time
        {
            get { return _time; }
        }
		
		public LoginCommand () : base (GaduConstants.CMD_OUT_LOGIN)
		{
			
		}
		
		protected override void Write (BinaryWriter writer)
		{
			writer.Write(_number);
            writer.Write (_hash_type);
            
            for (int i = 0; i < _hash.Length; i++)
                writer.Write (_hash[i]);
            
            writer.Write(_status);
            writer.Write(_version);
            writer.Write(_unknown1);
            writer.Write(0);
            writer.Write(_local_port);
            writer.Write(0);
            writer.Write(_external_port);
            writer.Write(_image_size);
            writer.Write(_unknown2);
		}
        
        public override string ToString ()
        {
        	return String.Empty;
        }
    }
}